package com.transaction.seataorder;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.transaction.seataorder.mapper.UserMapper;
import com.transaction.seataorder.model.User;
import com.transaction.seataorder.server.IUserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;

/**
 * @author ausu
 * @version 1.0
 * @description: TODO
 * @date 2022/12/30 13:42
 */
@SpringBootTest
public class FastAutoGeneratorDemo {

    @Test
    public void fastAutoGeneratorDemo() {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/seata_stock?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root")
                .globalConfig(builder -> {
                    builder.author("lwd") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://Datasourse"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.dynamic") // 设置父包名
                            .moduleName("datasourse") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapper, "D://Datasourse")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("stock_tbl") // 设置需要生成的表名
                            .addTablePrefix("tbl_", "t_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private IUserService userService;

    @Test
    public void test() {
//        LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper
//                .like(User::getName,"李");
//        updateWrapper.set(User::getName,"李小二")
//                .set(User::getRole,"用户")
//                .set(User::getSex,"男");
        User user = new User();
        user.setName("李d");
        boolean b = userService.save(user);
//        int insert = userMapper.insert(user);
        System.out.println("操作成功："+b);
    }

}
